<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="用户id" prop="userId">
      <el-input v-model="dataForm.userId" placeholder="用户id"></el-input>
    </el-form-item>
    <el-form-item label="学号" prop="stuId">
      <el-input v-model="dataForm.stuId" placeholder="学号"></el-input>
    </el-form-item>
    <el-form-item label="入学年份" prop="enrollmentYear">
      <el-input v-model="dataForm.enrollmentYear" placeholder="入学年份"></el-input>
    </el-form-item>
    <el-form-item label="班级id" prop="classId">
      <el-input v-model="dataForm.classId" placeholder="班级id"></el-input>
    </el-form-item>
    <el-form-item label="行政班id" prop="administrativeClazzId">
      <el-input v-model="dataForm.administrativeClazzId" placeholder="行政班id"></el-input>
    </el-form-item>
    <el-form-item label="语文班级id" prop="chineseClazzId">
      <el-input v-model="dataForm.chineseClazzId" placeholder="语文班级id"></el-input>
    </el-form-item>
    <el-form-item label="数学班级id" prop="matheClazzId">
      <el-input v-model="dataForm.matheClazzId" placeholder="数学班级id"></el-input>
    </el-form-item>
    <el-form-item label="英语班级id" prop="englishClazzId">
      <el-input v-model="dataForm.englishClazzId" placeholder="英语班级id"></el-input>
    </el-form-item>
    <el-form-item label="物理班级id" prop="physicsClazzId">
      <el-input v-model="dataForm.physicsClazzId" placeholder="物理班级id"></el-input>
    </el-form-item>
    <el-form-item label="化学班级id" prop="chemistryClazzId">
      <el-input v-model="dataForm.chemistryClazzId" placeholder="化学班级id"></el-input>
    </el-form-item>
    <el-form-item label="生物班级id" prop="biologyClazzId">
      <el-input v-model="dataForm.biologyClazzId" placeholder="生物班级id"></el-input>
    </el-form-item>
    <el-form-item label="政治班级id" prop="politicsClazzId">
      <el-input v-model="dataForm.politicsClazzId" placeholder="政治班级id"></el-input>
    </el-form-item>
    <el-form-item label="历史班级id" prop="historyClazzId">
      <el-input v-model="dataForm.historyClazzId" placeholder="历史班级id"></el-input>
    </el-form-item>
    <el-form-item label="地理班级id" prop="geographyClazzId">
      <el-input v-model="dataForm.geographyClazzId" placeholder="地理班级id"></el-input>
    </el-form-item>
    <el-form-item label="组合id" prop="accountCombinationId">
      <el-input v-model="dataForm.accountCombinationId" placeholder="组合id"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="创建者" prop="createBy">
      <el-input v-model="dataForm.createBy" placeholder="创建者"></el-input>
    </el-form-item>
    <el-form-item label="更新时间" prop="updateTime">
      <el-input v-model="dataForm.updateTime" placeholder="更新时间"></el-input>
    </el-form-item>
    <el-form-item label="更新者" prop="updateBy">
      <el-input v-model="dataForm.updateBy" placeholder="更新者"></el-input>
    </el-form-item>
    <el-form-item label="对应教师id" prop="teacherId">
      <el-input v-model="dataForm.teacherId" placeholder="对应教师id"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          userId: '',
          stuId: '',
          enrollmentYear: '',
          classId: '',
          administrativeClazzId: '',
          chineseClazzId: '',
          matheClazzId: '',
          englishClazzId: '',
          physicsClazzId: '',
          chemistryClazzId: '',
          biologyClazzId: '',
          politicsClazzId: '',
          historyClazzId: '',
          geographyClazzId: '',
          accountCombinationId: '',
          createTime: '',
          createBy: '',
          updateTime: '',
          updateBy: '',
          teacherId: ''
        },
        dataRule: {
          userId: [
            { required: true, message: '用户id不能为空', trigger: 'blur' }
          ],
          stuId: [
            { required: true, message: '学号不能为空', trigger: 'blur' }
          ],
          enrollmentYear: [
            { required: true, message: '入学年份不能为空', trigger: 'blur' }
          ],
          classId: [
            { required: true, message: '班级id不能为空', trigger: 'blur' }
          ],
          administrativeClazzId: [
            { required: true, message: '行政班id不能为空', trigger: 'blur' }
          ],
          chineseClazzId: [
            { required: true, message: '语文班级id不能为空', trigger: 'blur' }
          ],
          matheClazzId: [
            { required: true, message: '数学班级id不能为空', trigger: 'blur' }
          ],
          englishClazzId: [
            { required: true, message: '英语班级id不能为空', trigger: 'blur' }
          ],
          physicsClazzId: [
            { required: true, message: '物理班级id不能为空', trigger: 'blur' }
          ],
          chemistryClazzId: [
            { required: true, message: '化学班级id不能为空', trigger: 'blur' }
          ],
          biologyClazzId: [
            { required: true, message: '生物班级id不能为空', trigger: 'blur' }
          ],
          politicsClazzId: [
            { required: true, message: '政治班级id不能为空', trigger: 'blur' }
          ],
          historyClazzId: [
            { required: true, message: '历史班级id不能为空', trigger: 'blur' }
          ],
          geographyClazzId: [
            { required: true, message: '地理班级id不能为空', trigger: 'blur' }
          ],
          accountCombinationId: [
            { required: true, message: '组合id不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          createBy: [
            { required: true, message: '创建者不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ],
          updateBy: [
            { required: true, message: '更新者不能为空', trigger: 'blur' }
          ],
          teacherId: [
            { required: true, message: '对应教师id不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/eas/easbasicstu/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.userId = data.easBasicStu.userId
                this.dataForm.stuId = data.easBasicStu.stuId
                this.dataForm.enrollmentYear = data.easBasicStu.enrollmentYear
                this.dataForm.classId = data.easBasicStu.classId
                this.dataForm.administrativeClazzId = data.easBasicStu.administrativeClazzId
                this.dataForm.chineseClazzId = data.easBasicStu.chineseClazzId
                this.dataForm.matheClazzId = data.easBasicStu.matheClazzId
                this.dataForm.englishClazzId = data.easBasicStu.englishClazzId
                this.dataForm.physicsClazzId = data.easBasicStu.physicsClazzId
                this.dataForm.chemistryClazzId = data.easBasicStu.chemistryClazzId
                this.dataForm.biologyClazzId = data.easBasicStu.biologyClazzId
                this.dataForm.politicsClazzId = data.easBasicStu.politicsClazzId
                this.dataForm.historyClazzId = data.easBasicStu.historyClazzId
                this.dataForm.geographyClazzId = data.easBasicStu.geographyClazzId
                this.dataForm.accountCombinationId = data.easBasicStu.accountCombinationId
                this.dataForm.createTime = data.easBasicStu.createTime
                this.dataForm.createBy = data.easBasicStu.createBy
                this.dataForm.updateTime = data.easBasicStu.updateTime
                this.dataForm.updateBy = data.easBasicStu.updateBy
                this.dataForm.teacherId = data.easBasicStu.teacherId
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/eas/easbasicstu/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'userId': this.dataForm.userId,
                'stuId': this.dataForm.stuId,
                'enrollmentYear': this.dataForm.enrollmentYear,
                'classId': this.dataForm.classId,
                'administrativeClazzId': this.dataForm.administrativeClazzId,
                'chineseClazzId': this.dataForm.chineseClazzId,
                'matheClazzId': this.dataForm.matheClazzId,
                'englishClazzId': this.dataForm.englishClazzId,
                'physicsClazzId': this.dataForm.physicsClazzId,
                'chemistryClazzId': this.dataForm.chemistryClazzId,
                'biologyClazzId': this.dataForm.biologyClazzId,
                'politicsClazzId': this.dataForm.politicsClazzId,
                'historyClazzId': this.dataForm.historyClazzId,
                'geographyClazzId': this.dataForm.geographyClazzId,
                'accountCombinationId': this.dataForm.accountCombinationId,
                'createTime': this.dataForm.createTime,
                'createBy': this.dataForm.createBy,
                'updateTime': this.dataForm.updateTime,
                'updateBy': this.dataForm.updateBy,
                'teacherId': this.dataForm.teacherId
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
